const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    user: {},
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },


  onPullDownRefresh: function () {
    this.getUserData();
    this.getEquipmentNumber();
    wx.stopPullDownRefresh();
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.hideHomeButton();
    this.getUserData();
    this.getEquipmentNumber();
  },

  //跳转至个人中心
  navPersonal() {
    wx.navigateTo({
      url: '../personal/personal',
    })
  },

  //跳转到系统公告
  navSystemMsg() {
    wx.navigateTo({
      url: "../systemMsg/systemMsg"
    })
  },


  //跳转到设备管理
  navDeviceManage() {
    wx.navigateTo({
      url: '/pages/partner/equipment/equipment?is_repair=1',
    });
  },
  navDeviceLibrary() {
    wx.navigateTo({
      url: '../libraryList/libraryList?type=1',
    });
  },

  //跳转滤芯更换
  navFilterCoreChange() {
    wx.navigateTo({
      url: '../filterCoreChange/filterCoreChange',
    });
  },



  //跳转到添加设备
  navAddDevice() {
    wx.navigateTo({
      url: '/pages/partner/equipmentEdit/equipmentEdit?type=1&is_repair=1',
    });
  },
  //打水码绑定
  thrashBinding() {
    wx.navigateTo({
      url: '../thrashBinding/thrashBinding',
    });
  },
  //跳转到设备调试
  navDeviceDebug() {
    app.ajax({
      url: 'Manage/User/getManageInfo',
      data: {},
      success: res => {
        if (res.data.code == 200) {
          if (res.data.data.is_auth == 1) {
            wx.navigateTo({
              // url: '../deviceManage/deviceManage?type=2',
              url: "/package/pages/debug/entrance/entrance"
            });
          } else {
            app.showToast('您没有相关权限！', "none", 2000, function () {});
          }
        } else {
          app.showToast("获取用户信息失败");
        }
      }
    })
  },

  //跳转到版本更新记录

  navUpdateVersion() {
    wx.navigateTo({
      url: '../updateVersion/list',
    });
  },


  //获取设备参数总和
  getEquipmentNumber() {
    app.ajax({
      url: 'Manage/Equipment/statistics',
      method: "POST",
      data: {},
      success: res => {
        if (res.data.code == 1000) {
          this.setData({
            equipment: res.data.data
          })
        } else {
          app.showToast("获取设备数量失败");
        }
      }
    })
  },


  //获取账号信息
  getUserData() {
    app.ajax({
      url: 'Manage/User/getManageInfo',
      method: "POST",
      data: {},
      success: res => {
        if (res.data.code == 200) {
          this.setData({
            user: res.data.data
          })
        } else {
          app.showToast("获取用户信息失败");
        }
      }
    })
  },

  //根据类型跳转到设备管理
  navDeviceManageFormType(e) {
    const {
      type
    } = e.currentTarget.dataset;
    wx.navigateTo({
      url: "/pages/partner/equipment/equipment?is_repair=1&param=" + type
    })
  }


})